const btn = document.querySelector('#btn-register')
btn.addEventListener('click', async function () {
    const form = document.querySelector('.register-form')
    //获取用户输入内容
    const data = serialize(form, { hash: true, empty: true })
    const { username, password } = data

    if (username.length < 8 || username.length > 30) {
        showToast('用户名是8~30位')
        return
    }
    if (password.length < 6 || password.length > 30) {
        showToast('密码是6~30位')
        return
    }

    try {
        //发送请求
        const { message } = await axios.post('/register', data)
        showToast(message)

    } catch (err) {
        console.dir(err)
        showToast(err.response.data.message)
    }
})